import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.List;

/**
 * jedis 操作 redis List基本命令
 */
public class RedisDemoList {

    public static void test1(Jedis jedis) {
        System.out.println("lpush 和 lrange");
        jedis.flushDB();

        jedis.lpush("key", "111", "222", "333");
        List<String> result = jedis.lrange("key", 0, -1);
        System.out.println("result: " + result);
    }
    public static void test2(Jedis jedis) {
        System.out.println("rpush  rpop lpop");
        jedis.flushDB();

        jedis.rpush("key", "111", "222","333");
//        System.out.println(jedis.rpop("key"));
//        System.out.println(jedis.rpop("key"));
//        System.out.println(jedis.rpop("key"));
//        System.out.println(jedis.rpop("key"));

        System.out.println(jedis.lpop("key"));
        System.out.println(jedis.lpop("key"));
        System.out.println(jedis.lpop("key"));
        System.out.println(jedis.lpop("key"));
    }
    public static void test3(Jedis jedis) {
        System.out.println(" blpop 和 brpop");
        jedis.flushDB();

        List<String> resutl = jedis.blpop(60, "key");
        System.out.println("key: " + resutl.get(0));
        System.out.println("value: " + resutl.get(1));
    }
    public static void test4(Jedis jedis) {
        System.out.println("llen");
        jedis.flushDB();


        jedis.rpush("key", "111", "222","333");
        long llen = jedis.llen("key");

        System.out.println("llen: " + llen);
    }
    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("tcp://127.0.0.1:8888");

        try(Jedis jedis = jedisPool.getResource()) {
            // test1(jedis);
            // test2(jedis);
            // test3(jedis);
            test4(jedis);
        }
    }
}
